﻿package com.webbei.friendcenter.dao.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;

import com.webbei.friendcenter.dao.MyFriendCenterDao;
import com.webbei.pojo.CommentCustomShow;
import com.webbei.pojo.Commission;
import com.webbei.pojo.Customcomment;
import com.webbei.pojo.Customer;
import com.webbei.pojo.Customs;
import com.webbei.pojo.Display;
import com.webbei.pojo.LoveCar;
import com.webbei.pojo.Messages;
import com.webbei.pojo.Orders;
import com.webbei.pojo.Report;
import com.webbei.pojo.Userhot;
import com.webbei.pojo.friends;

public class MyFriendCenterDaoImpl implements MyFriendCenterDao{

	private SqlSession session;
	public SqlSession getSession() {
		return session;
	}
	public void setSession(SqlSession session) {
		this.session = session;
	}
	  
	
	public List getAllFriendsNameByOwnerName(String ownName) {
		List<Customs> list=session.selectList("cust.getAllCustoms",ownName);
		return list;
	}
	public int getMyFriendsCount(String string) {
		return (Integer)session.selectOne("cust.getAllCustomsCount",string);
	}
	public Customer getCustomerByUserName(String uname) {
		return (Customer)session.selectOne("cust.getCustomerByUsername",uname);
	}
	public Userhot getUserhotByUserName(String uname) {
		return (Userhot)session.selectOne("userhot.getUserhotByUsername",uname);
	}
	public int getCustomerIDByUserName(String uname) {
		return (Integer)session.selectOne("customer.getCustomerIdByUserName",uname);
	}
	public List<LoveCar> getLoveCarsbyUserID(int user_id) {
		List<LoveCar> list=session.selectList("lovecars.getLoveCarsByCustomersID",user_id);
		return list;
	}
	public List<Userhot> getAllFriendsByUserName(String uname) {
		List<Userhot> list=session.selectList("userhot.getAllFriendsByUserName",uname);
		return list;
	}
	public List<Orders> getAllcustomsByUserName(String uname) {
		 List<Orders> list=session.selectList("cust.getCustomsByUsername",uname);
		 return list;
	}
	
	public List<Customcomment> getAllCommentByUsername(String uname) {
		List<Customcomment> list=session.selectList("Customcomment.getALLCommentByUsername",uname);
		return list;
	}
	public int InsertNewComment(Long customid, String name,
			String textContent, Date currentDate,int sourse) {
			Customcomment comment=new Customcomment();
			comment.setCustomId(customid);
			comment.setUserName(name);
			comment.setCommentContent(textContent);
			comment.setCommentTime(currentDate);
			comment.setCommentSourse(sourse);
			System.out.println(comment);
			int i=session.insert("Customcomment.insertComment",comment);
			return i;
	}
	public List getAllFriendsChangeByOwnName(String string){
		return session.selectList("friends.getAllFriendsChangeByUserName",string);
	}
	public List<Display> getAllFriendsChangeShareByOwnName(String uname) {
		return session.selectList("friends.getAllFriendsChangeShareByUserName",uname);
	}
	public int insertMessageEachOther(Messages message) {
		int i=session.insert("Messages.newMessage",message);
		return i;
	}
	public List<Messages> getALLMessagesByUserName(String uname) {
		return session.selectList("Messages.getAllmessagesByUsername",uname);
	}
	public List<Orders> getAllcustomsShareByUserName(String uname) {
		List<Orders> list=session.selectList("cust.getCustomsShareByUsername",uname);
		return list;
	}
	public int addNewFriendByOwnUser(String ownUser, String addUser) {
		friends f=new friends();
		f.setMyName(ownUser);
		f.setFriendName(addUser);
		return session.insert("friends.insertNewFroend",f);
	}
	public List<Orders> getCostMoneyMessageByUserName(String uname) {
		List<Orders> list=session.selectList("cust.getCustomsMoneyMessage",uname);
		return list;
	}
	public List<CommentCustomShow> getCommentCustomShow(String uname) {
		List<CommentCustomShow> list=session.selectList("cust.getCommentCustomShow",uname);
		return list;
	}
	public int insertNewReport(String reportName, String beReportName,
			String reprotContent, Date reportTime, int customId) {
		Report re=new Report();
		re.setReporterName(reportName);
		re.setBereporterName(beReportName);
		re.setReportcontent(reprotContent);
		re.setReporttime(reportTime);
		re.setCommentId(customId);
		int i=session.insert("report.insertNewReport",re);
		return i;
		
	}
	public int UnameIsSessionNameFriend(String sessionInName, String uname) {
		int i=0;
		friends f=new friends();
		f.setMyName(sessionInName);
		f.setFriendName(uname);
		i=(Integer) session.selectOne("friends.UnameIsSessionNameFriend",f);
		return i;
	}
	@Override
	public int checkNameByUname(String uname) {
		int i=0;
		i=(Integer) session.selectOne("customer.getCustomerCount2",uname);
		System.out.println("999999999999999999:"+i);
		return i;
	}
	@Override
	public List<Commission> getAllCommissionByUserName(String username) {
			List<Commission> list=null;
			list=session.selectList("commission.getAllCommission",username);
			return list;
	}
	@Override
	public boolean IsExistTheUserName(String uname) {
		int i=0;
		i=(Integer) session.selectOne("customer.getCustomerCount2",uname);
		if(i>0){
			return true;
		}else{
			return false;
		}
		
	}
	@Override
	public List<Customcomment> getALLCommentISShareByUsername(String uname) {
		List<Customcomment> list=session.selectList("Customcomment.getALLCommentISShareByUsername",uname);
		return list;
	}
	@Override
	public List<Orders> getAllMyPartInShareByUserName(String uname) {
		System.out.println("uname:"+uname);
		List<Orders> list=session.selectList("collection.getAllMyPartInShare",uname);
		return list;
	}
	@Override
	public List<Customcomment> getAllCommentPartInShareByUserName(String uname) {
		List<Customcomment> list=session.selectList("Customcomment.getALLCommentPartInByUsername",uname);
		return list;
	}
	@Override
	public String getCustomUploadFileContentInCustoms(int customId) {
		String CustomUploadFileContent=(String)session.selectOne("cust.CustomUploadFileContent",customId);
		return CustomUploadFileContent;
	}
	@Override
	public int CustomUploadFileUpdateByCustomId(int customId,
			String filesFileName) {
		Map m=new HashMap();
		m.put("a",customId);
		m.put("b",filesFileName);
		System.out.println("map:"+m);
		return session.update("cust.UpdateCustomUploadFile",m);
		
	}
	@Override
	public Customcomment getTheLastCommentByCustomId(Map m) {
		Customcomment comment=(Customcomment) session.selectOne("Customcomment.getthelastcomment",m);
		return comment;
	}
	@Override
	public int getComemntCountByCustomId(Map m) {
		int i =(Integer)session.selectOne("Customcomment.commentCountByCustomId",m);
		return i;
		
	}
	@Override
	public List<Userhot> getAllFriendsByUserNameOrderBycarBrind(String uname,
			String carBrind) {
		Map m=new HashMap();
		m.put("a", uname);
		m.put("b", carBrind);
		List<Userhot> list=session.selectList("userhot.getAllFriendsByUserNameOrderByCarBrind",m);
		return list;
	}
	@Override
	public List<Customs> getAllNoPayCanShareCustomByUserName(String uname) {
		List<Customs> list=null;
		list=session.selectList("cust.getallcustombyunameandcanshare", uname);
		return list;
	}
	@Override
	public List<Customcomment> getALLCommentISNoPayCanShareByUsername(
			String uname) {
		List<Customcomment> list=session.selectList("Customcomment.getALLCommentIsNoPay",uname);
		return list;
	}
	@Override
	public String getCustomUploadFileContent(int customId) {
		String CustomUploadFileContent=(String)session.selectOne("cust.getTheUpLoadFileContent",customId);
		return CustomUploadFileContent;
	}
	@Override
	public int UploadFileContentInCustomsByCustomId(int customId, String string) {
		Map m=new HashMap();
		m.put("a",customId);
		m.put("b",string);
		System.out.println("map:"+m);
		return session.update("cust.updatecustomfileuploadfile",m);
	}
	@Override
	public List<Customs> getAllMyPartInShareNoPayInCustomByUserName(String uname) {
		List<Customs> list=null;
		list=session.selectList("cust.allpartinsharenopayincustom", uname);
		return list;
	}
	@Override
	public List<Customcomment> getTheCommentPartInShareNoPayByUserName(
			String uname) {
		List<Customcomment> list=session.selectList("Customcomment.getallcommentpartinsharenopay",uname);
		return list;
	}
	@Override
	public List<Customs> getAllNotBuycustomsByUserName(String uname) {
		List<Customs> list=null;
		list=session.selectList("cust.getallcustomnotbuyincustoms", uname);
		return list;
	}
	@Override
	public List<Customcomment> getAllNotBuyCustomCommentByUserName(String uname) {
		List<Customcomment> list=session.selectList("Customcomment.getALLCommentIsNoPay",uname);
		return list;
	}
	@Override
	public List<Customcomment> getAllCustomShareCommentByUserName(String uname) {
		List<Customcomment> list=session.selectList("Customcomment.getALLCommentISShareByUsername",uname);
		return list;
	}
	@Override
	public List<Display> getAllFriendsChangeCustomByOwnName(String uname) {
		return session.selectList("friends.getallfriendschangecustombyownname",uname);
	}
	@Override
	public List<Display> getAllFriendsChangeCustomShareByOwnName(String uname) {
		return session.selectList("friends.getallfriendschangecustomsharebyoownname",uname);
	}
	@Override
	public List<Commission> getAllCommissionFromCustomByUserName(String uname) {
		List<Commission> list=null;
		list=session.selectList("commission.getallcommissionfromcustom",uname);
		return list;
	}
	@Override
	public List<Display> getAllPartShareInOrderByUserName(String uname) {
		return session.selectList("friends.getallpartshareinorderbyusername",uname);
	}
	@Override
	public List<Display> getAllPartShareInCustomByUserName(String uname) {
		return session.selectList("friends.getallpartshareincustombyusername",uname);
	}
	@Override
	public List<CommentCustomShow> getCommentOrderShow(String uname) {
		List<CommentCustomShow> list=session.selectList("cust.getCommentOrderShow",uname);
		return list;
	}
	@Override
	public int NewCustomers(String hpassword,
			String dmail, String truename, String phonenumber,String touImage){
		Map<String,Object> m=new HashMap<String,Object>();
		m.put("password", hpassword);
		m.put("email", dmail);
		m.put("realname", truename);
		m.put("phonenumber", phonenumber);
		m.put("touImage", touImage);
		return session.insert("customer.newcustomers", m);
	}
	@Override
	public int newDesigners(String dmail, String identitycard,
			String newFileName) {
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("dmail", dmail);
		map.put("identitycard", identitycard);
		map.put("newFileName", newFileName);
		return session.insert("designers.newdesigners",map);
	}
	@Override
	public int updateCustomersByEmail(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return session.update("customer.updatecustomers",map);
	}
	
}
